function schedulability=PT_schedulability_test(task_Properties)

%Initialize
%{
%this matrix is just for test
task_Properties=[1 1 30 30 1;
                 2 2 50 50 2;
                 3 3 60 60 3];
%}
            
%the number of all tasks according to the matrix size
[task_Num,~]=size(task_Properties);
schedulability=0;

%Extract Ci, Ci_0, Ti, Di, Li
task_Exe_Time=task_Properties(:,1)';
task_Exe_Time_Overload=task_Properties(:,2)';
task_Period=task_Properties(:,3)';
task_Due_Time=task_Properties(:,4)';
task_Criticality=task_Properties(:,5)';

%reform the task set
%the task set is arranged from low criticality to high criticality
%we should let high criticality task have high priority, so we slice their
%period from up to down, note that a task may be cut more than once.
for i=1:task_Num-1
    for j=i+1:task_Num
        if task_Period(j)>task_Period(i)
            divider=ceil(task_Period(j)/task_Period(i));
            task_Period(j)=task_Period(j)/divider;
        end
    end
end

N_divider=task_Properties(:,3)'./task_Period;

task_Period_Sliced=task_Period;
task_Exe_Time_O_Sliced=task_Exe_Time_Overload./N_divider;

%in the equation to calculate Ri, we still use the original version ot task
%parameter
task_Period=task_Properties(:,3)';






%initializing the vector to accelerate the code
task_Response_Time=zeros(1,task_Num);

%just consider RMA
task_Priority=1./task_Period;

for i=1:task_Num
    
    R=task_Exe_Time_Overload(i);
    R_last=0;
    %get the response time of task i
    while(R~=R_last)&&(R<=task_Due_Time(i))
        R_last=R;
        
        %those with a smaller period will have a higher priority
        %they will preempt task i and Ri will be larger
        %then more jobs of higher priority tasks can be inside
        sum_temp=0;        
        for j=1:task_Num
            %don't forget the task itself, so use ">="
            if task_Priority(j)>=task_Priority(i) 
                %the equation is from the "3 implemention paper"
                %any task j who preempt task i will not overload, because
                %they have higher criticality in PT
                %Note that even their WCET is Cin, for each slice they
                %spend Cio/nj, just for their safety concern because they
                %do not know if they will overload
                if j==i
                    %we assume the task itself will overload
                    sum_temp=sum_temp+task_Exe_Time_Overload(j);  
                else
                    %all higher criticality tasks will not overload
                    sum_temp=sum_temp+floor(R/task_Period(j))*task_Exe_Time(j)+min(ceil(mod(R,task_Period(j))/(task_Period_Sliced(j)))*task_Exe_Time_O_Sliced(j),task_Exe_Time(j)); 
                end   
            end
        end
        R=sum_temp;
    end 
    
   task_Response_Time(i)=max(R,task_Period(i)-task_Period_Sliced(i)+task_Exe_Time_O_Sliced(i));
end

if(sum((task_Due_Time-task_Response_Time)<0)==0)
    schedulability=1;
end




